package com.springcloud.util.model;

import com.itextpdf.text.BaseColor;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/**
 * @Description: TODO
 * @Create by: charlie
 * @Date: 2021/11/22 17:14
 */

@Data
public class BaseColorFeature {
    private BaseColor baseColor = null;
    public BaseColorFeature(String hexColor) {
        if (StringUtils.isNotBlank(hexColor)) {
            if (hexColor.startsWith("#") && hexColor.length() == 7) {
                String r = hexColor.substring(1, 3);
                String g = hexColor.substring(3, 5);
                String b = hexColor.substring(5, 7);
                int rv = NumberUtils.getNumberFormHex(r);
                int gv = NumberUtils.getNumberFormHex(g);
                int bv = NumberUtils.getNumberFormHex(b);
                this.baseColor = new BaseColor(rv, gv, bv);
            }
        }
    }

    public BaseColorFeature(String hexColor,BaseColor defaultColor) {
        if (StringUtils.isNotBlank(hexColor)) {
            if (hexColor.startsWith("#") && hexColor.length() == 7) {
                String r = hexColor.substring(1, 3);
                String g = hexColor.substring(3, 5);
                String b = hexColor.substring(5, 7);
                int rv = NumberUtils.getNumberFormHex(r);
                int gv = NumberUtils.getNumberFormHex(g);
                int bv = NumberUtils.getNumberFormHex(b);
                this.baseColor = new BaseColor(rv, gv, bv);
                return;
            }
        }
        this.baseColor=defaultColor;
    }
}
